//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __ELASTOS__ELADBGAGENT__ELADBG_H__
#define __ELASTOS__ELADBGAGENT__ELADBG_H__

#include <eladef.h>

#ifdef _ELADBGAGENT

//#define EVC_ELADBG_MODULE_PATH
//"D:\\Elastos20.SDK\\obj\\arm_bulverde\\evc.dbg\\"
#define STATUS_UNSUCCESSFUL 0xC0000001L
#define STATUS_SUCCESS      0x00000000L
#define STATUS_CONTINUE     0x00000001L

#define EXC_BREAKPOINT      0x80000003

/* Exception Flags
 */
enum
{
    EXC_FLAG_CONTINUABLE        = 0x0L, /* Continuable exception */
    EXC_FLAG_NONCONTINUABLE     = 0x1L  /* Noncontinuable exception */
};

/* Debugging event code
 */
enum
{
    DBG_EXCEPTION_EVENT         = 1L,
    DBG_CREATE_THREAD_EVENT     = 2L,
    DBG_CREATE_PROCESS_EVENT    = 3L,
    DBG_EXIT_THREAD_EVENT       = 4L,
    DBG_EXIT_PROCESS_EVENT      = 5L,
    DBG_LOAD_DLL_EVENT          = 6L,
    DBG_UNLOAD_DLL_EVENT        = 7L,
    DBG_OUTPUT_STRING_EVENT     = 8L
};

typedef struct _DBG_EXCEPTION
{
    UInt32    FirstChance;
    UInt32    ExceptCode;
    UInt32    ExceptFlags;
    UInt32    ExceptInfo;
} DBG_EXCEPTION, *PDBG_EXCEPTION;

typedef struct _DBG_LOAD_DLL
{
    Address  BaseOfDll;
    UInt32     SizeOfDll;
    UInt32     NameOffset;
    UInt32     NameLength;
} DBG_LOAD_DLL, *PDBG_LOAD_DLL;

typedef struct _DBG_EVENT
{
    UInt32    EventCode;
    UInt32    ProcessId;
    UInt32    ThreadId;
    union
    {
        DBG_EXCEPTION Exception;
        DBG_LOAD_DLL  LoadDll;
    } u;
} DBG_EVENT, *PDBG_EVENT;

/* Debug transport APIs
 */
enum
{
    DbgReadVirtualMemoryApi      = 0x00003130L,
    DbgWriteVirtualMemoryApi     = 0x00003131L,
    DbgGetContextApi             = 0x00003132L,
    DbgSetContextApi             = 0x00003133L,
    DbgMarkBreakPointApi         = 0x00003134L,
    DbgClearBreakPointApi        = 0x00003135L,
    DbgContinueApi               = 0x00003136L,
    DbgReadControlSpaceApi       = 0x00003137L,
/*  DbgWriteControlSpaceApi      = 0x00003138L, */
/*  DbgReadIoSpaceApi            = 0x00003139L, */
/*  DbgWriteIoSpaceApi           = 0x0000313AL, */
    DbgRebootApi                 = 0x0000313BL,
/*  DbgContinueApi2              = 0x0000313CL, */
/*  DbgReadPhysicalMemoryApi     = 0x0000313DL, */
/*  DbgWritePhysicalMemoryApi    = 0x0000313EL, */
/*  DbgQuerySpecialCallsApi      = 0x0000313FL, */
/*  DbgSetSpecialCallApi         = 0x00003140L, */
/*  DbgClearSpecialCallsApi      = 0x00003141L, */
/*  DbgSetInternalBreakPointApi  = 0x00003142L, */
/*  DbgGetInternalBreakPointApi  = 0x00003143L, */
/*  DbgReadIoSpaceExtendedApi    = 0x00003144L, */
/*  DbgWriteIoSpaceExtendedApi   = 0x00003145L, */
    DbgGetVersionApi             = 0x00003146L,
/*  DbgMarkBreakPointExApi       = 0x00003147L, */
/*  DbgClearBreakPointExApi      = 0x00003148L, */
/*  DbgCauseBugCheckApi          = 0x00003149L, */
    DbgKillProcessApi            = 0x0000314AL,
    DbgGetModeApi                = 0x0000315AL,
    DbgPrintStringApi            = 0x00003230L,  /* Below are internal APIs */
/*  DbgGetStringApi              = 0x00003231L, */
    DbgConnectApi                = 0x96969696L,
    DbgResetApi                  = 0x69696969L,
};

typedef struct _DBGBUF
{
    UInt32  Length;
    UInt32  MaxLength;
    PByte  Buffer;
} DBGBUF, *PDBGBUF;

typedef struct _DBG_SYMINFO{
    UInt32 BaseAddress;
    UInt32 ImageSize;
    char  SymName[256];
}DBG_SYMINFO,*PDBG_SYMINFO;

typedef struct _DBG_VERSION
{
    UInt16 MajorVersion;
    UInt16 MinorVersion;
    UInt16 ProtocolVersion;
    UInt16 Reserved;
} DBG_VERSION, *PDBG_VERSION;

/* Data contents immediately follow the structure.
 */
typedef struct _DBG_MEMORY
{
    Address TargetAddress;
    UInt32  TransferCount;
    UInt32  ActualBytes;
} DBG_MEMORY, *PDBG_MEMORY;

/* Breakpoint records immediately follow
 */
typedef struct _DBG_BREAKPOINT
{
    UInt32  BreakPointCount;
    UInt32  Reserved;
} DBG_BREAKPOINT, *PDBG_BREAKPOINT;

/* Context record follows
 */
typedef struct _DBG_CONTEXT
{
    UInt32  ContextFlags;
} DBG_CONTEXT, *PDBG_CONTEXT;

typedef struct _DBG_CONTINUE
{
    Int32   ContinueStatus;
} DBG_CONTINUE, *PDBG_CONTINUE;

/* For print string, the Null terminated string to print
 * immediately follows the message
 */
typedef struct _DBG_PRINT_STRING
{
    UInt32 LengthOfString;
    Byte   buf[4];
} DBG_PRINT_STRING, *PDBG_PRINT_STRING;

/* For get string, the Null terminated prompt string
 * immediately follows the message. The LengthOfStringRead
 * field initially contains the maximum number of characters
 * to read. Upon reply, this contains the number of bytes actually
 * read. The data read immediately follows the message.
 */
typedef struct _DBG_GET_STRING
{
    UInt32 LengthOfPromptString;
    UInt32 LengthOfStringRead;
    Byte   buf[4];
} DBG_GET_STRING, *PDBG_GET_STRING;

//This type for DgbStateApi, use to get the mode of the debuger
#define MODE_USER_DEUBG   0x10000000
#define MODE_KERNEL_DEUBG 0x10101010
typedef struct _DBG_MODE
{
    UInt32 DebugerMode;
} DBG_MODE, * PDBG_MODE;

typedef struct _DBG_MESSAGE
{
    UInt32  ApiNumber;
    Int32   ReturnStatus;
    UInt32  ProcessId;
    UInt32  ThreadId;
    union
    {
        DBG_VERSION      Version;
        DBG_MEMORY       Memory;
        DBG_BREAKPOINT   BreakPoint;
        DBG_CONTEXT      Context;
        DBG_CONTINUE     Continue;

/*      DBG_CONTINUE2               Continue2;             */
/*      DBG_READ_WRITE_IO           ReadWriteIo;           */
/*      DBG_READ_WRITE_IO_EXTENDED  ReadWriteIoExtended;   */
/*      DBG_QUERY_SPECIAL_CALLS     QuerySpecialCalls;     */
/*      DBG_SET_SPECIAL_CALL        SetSpecialCall;        */
/*      DBG_SET_INTERNAL_BREAKPOINT SetInternalBreakpoint; */
/*      DBG_GET_INTERNAL_BREAKPOINT GetInternalBreakpoint; */

        DBG_PRINT_STRING            PrintString;
        DBG_GET_STRING              GetString;
        DBG_MODE                    Mode;

    } u;
} DBG_MESSAGE, *PDBG_MESSAGE;

#endif //_ELADBGAGENT

#endif //__ELASTOS__ELADBGAGENT__ELADBG_H__
